<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<link rel="stylesheet" href="${webcontext}/res/style/S.css" />
	<script type="text/javascript" src="${webcontext}/res/js/jquery.min.js"></script>
	<script type="text/javascript" src="${webcontext}/res/js/S.js"></script>
	<script type="text/javascript">
		$(function(){
			var tbl  =new S.Table({
				el:'#tbl01',
				dbclick:function(data){
					editLink(data);
				},
				menus:{
					'打开':function(tr){
						var idx = $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						window.open(data.logo);
					},
					'修改':function(tr){
						var idx = $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						editLink(data);
					},
					'删除':function(tr){
						var idx = $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						deleteLink([data]);
					}
				},
				renders:{
					'logo':function(url){
						if(url){
							return '<img src="'+url+'" style="max-width:100px;max-height:30px; vertical-align: middle;background-color: #ccc;" />';
						}
						return '';
					}
				}
			});
			
			$('#btn_frlinks_add').click(function(){
				var dlg = new S.Dialog({
					title:'增加',
					width:400,
					height:230,
					modal:true,
					url:'${webcontext }/${pathvar.admin}/blog/frlinks/edit',
					buttons:{
						'确定':function(){
							if(!this.form.validate()){new S.Info({text:'请填写完整',type:'warn'}).show();return;}
							S.request({
								url:'${webcontext }/${pathvar.admin}/blog/frlinks/save',
								data:this.form.param(),
								success:function(){
									new S.Info({text:'操作成功',type:'success'}).show();
									dlg.remove();
									tbl.reload();
								}
							});
						},
						'关闭':function(){
							this.remove();
						}
					}
				});
				dlg.show();
			});
			
			function editLink(menu){
				var dlg = new S.Dialog({
					title:'编辑菜单',
					width:400,
					height:230,
					modal:true,
					url:'${webcontext }/${pathvar.admin}/blog/frlinks/edit?id='+menu.id,
					buttons:{
						'确定':function(){
							if(!this.form.validate()){new S.Info({text:'请填写完整',type:'warn'}).show();return;}
							S.request({
								url:'${webcontext }/${pathvar.admin}/blog/frlinks/update',
								data:this.form.param(),
								success:function(){
									new S.Info({text:'操作成功',type:'success'}).show();
									tbl.reload();
									dlg.remove();
								}
							});
						},
						'关闭':function(){
							this.remove();
						}
					}
				});
				dlg.show();
			}
			
			$('#btn_frlinks_edit').click(function(){
				
				var items = tbl.getCheckedRow();
				if(items.length !=1){new S.Info({text:'请选择1个菜单',type:'warn'}).show();return;}
				
				editLink(items[0]);
			});
			
			function deleteLink(items){
				S.confirm('警告','确认要删除选中菜单?',function(){
					var ids = [];
					S.each(items,function(i,item){
						ids.push(item.id);
					});
					S.request({
						url:'${webcontext }/${pathvar.admin}/blog/frlinks/delete',
						data:{ids:ids.join(',')},
						success:function(){
							new S.Info({text:'操作成功',type:'success'}).show();
							tbl.reload();	
						}
					});
					
				},'danger');
			}
			
			$('#btn_frlinks_delete').click(function(){
				var items = tbl.getCheckedRow();
				if(items.length ==0){new S.Info({text:'请选择菜单',type:'warn'}).show();return;}
				deleteLink(items);
			});
		});	
	</script>
</head>
<body>
	<div class="filled-box">
		<div class="toolbar">
			<span class="btn" id="btn_frlinks_add"><i class="icons link"></i> 增加</span>
			<span class="btn" id="btn_frlinks_edit"><i class="icons link_edit"></i> 修改</span>
			<span class="btn" id="btn_frlinks_delete"><i class="icons link_delete"></i> 删除</span>
		</div>
		<div class="content">
			<table id="tbl01" height="600" ds="${webcontext }/${pathvar.admin}/blog/frlinks/list">
				<tr>
					<td width="30" seq></td>
					<td width="50" checkall></td>
					<td width="200">Logo</td>
					<td width="200">名称</td>
					<td>链接</td>
				</tr>
				<tr>
					<td>@{seq}</td>
					<td><input type="checkbox" name="id" value="@{id}" /></td>
					<td>@{logo}</td>
					<td>@{name}</td>
					<td>@{url}</td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>